<style scoped>
    .layui-form >>> .layui-form-select{
        z-index: inherit;
    }
</style>

<template>
    <div class="department">
        <fieldset class="layui-elem-field layui-field-title">
            <legend>修改数据项</legend>
        </fieldset>

        <form class="layui-form " >
            <input type="hidden" name="guid" placeholder="" autocomplete="off" :value="guid" class="layui-input">
            <div class="layui-form-item">
                <label class="layui-form-label">标准名称</label>
                <div class="layui-input-block">
                    <input type="text" name="qaname" :value="qamain.qaname" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">类型</label>
                <div class="layui-input-block">
                    <select type="text" name="type" lay-verify="required" class="layui-select" >
                        <option value="">请选择</option>
                        <option v-for="(typ, index) in types" :value="typ.dictkey" :selected="qamain.type == typ.dictkey">{{typ.dicttext}}</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-block">

                    <select   id="status"  name="status"  lay-filter="status" required   lay-search="">
                        <option value="0" :selected="qamain.status == 0">启用</option>
                        <option value="1" :selected="qamain.status == 1">禁用</option>
                    </select>

                </div>
            </div>


            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="submit">立即提交</button>
                    <button class="layui-btn layui-btn-primary" @click="$parent.back">返回</button>
                </div>
            </div>
        </form>
    </div>
</template>

<script>
    export default {
        name: 'QamainEdit',
        props: ['id'],
        data () {
            return {
                guid : this.id,
                adata: {},
                qamain:{},
                typeEmnu:[],
                costincomeEmnu:[],
                types: ''
            }
        },
        mounted() {
            let that = this;
            layui.use(['form'], function () {
                var form = layui.form,
                    layer = layui.layer;

                let loader = layer.load();
                //获取回显数据
                $.ajax({
                    url: '/trace/Qamain!listVUEPC.action',
                    data: {guid: that.guid},
                    type: "post",
                    dataType: "json",
                    success: function(res) {
                        console.log(res);
                        if (res.info != "error") {
                            that.qamain = res.info.rows[0];


                            form.render('select');
                        } else {
                            that.toast("系统错误");
                        }
                    },
                    complete: function () {
                        layer.close(loader);
                    }
                });
                //提交编辑过的数据
                form.on('submit(submit)', function (data) {
                    let loader = layer.load();
                    $.ajax({
                        url: '/trace/Qamain!update.action',
                        data: data.field,
                        type: "post",
                        dataType: "json",
                        success: function(res) {
                            if (res.info == "success") {
                                that.toast("修改成功");
                                that.$parent.switchPage('Qamain');
                            } else if (res.info == 'noDel') {
                                that.toast("数据已经被引用，不允许修改！");
                            } else{
                                that.toast("系统错误");
                            }
                        },
                        complete: function () {
                            layer.close(loader);
                        }
                    });
                    return false;
                });
            });
            this.getTypes();
        },
        updated() {
            layui.form.render();
        },
        methods: {
            back: function () {
                this.$parent.switchPage(this.$parent.refView);
            },
            getTypes: function() {
                let that = this;
                this.axios({
                    method: 'get',
                    responseType: 'json',
                    url: '/sales/Sellform!findDict.action',
                    params: {type: 40}
                }).then(response => {
                    if (response.statusText == "OK") {
                        that.types = response.data;
                    } else {
                        this.toastText('获取类型数据失败');
                    }
                });
            },
            getqamain: function (){

            }

        }
    }
</script>
